package org.example.service;

import java.util.List;

import org.example.dao.UserDao;
import org.example.model.User;
import org.springframework.stereotype.Component;

import com.camelgreen.baseclass.BaseManager;
import com.camelgreen.baseclass.EntityDao;
import com.camelgreen.page.Page;
import com.camelgreen.page.PageParameter;

@Component
public class UserManager extends BaseManager<User, String>{
	
	private UserDao userDao;
	//增加setXXXX()方法,spring就可以通过autowire自动设置对象属性
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	@Override
	protected EntityDao getEntityDao() {		
		return this.userDao;
	}

	public Page findByPageRequest(PageParameter pr) {
		return userDao.findByPageRequest(pr);
	}
	
	
	
	public void exec(){
		for(int i=0;i<10;i++){
			User user = new User();
			user.setName("jack"+i);
			userDao.save(user);
		}
//		PageParameter pr = new PageParameter();
//		pr.setFilters(null);
//		pr.setPageNumber(1);
//		pr.setPageSize(2);
//		pr.setSortColumns(null);
//		Page page = findByPageRequest(pr);
//		System.out.println(page.getResult().size());
		List<User> list = findAll();
		for(User user : list){
			System.out.println(user);
		}
	}
}
